<?php
namespace My\Controller;

use Utuo\BackgroundController;

class DistributionShopAdvController extends BackgroundController {
	
	public function _initialize() {
		$this->setControllerTitle("媒体广告管理");
		$this->setActionTitle(array(
			'index' => '媒体广告设置',
			'url' => '媒体地址',
		));
		$this->setActionNav('index,url');
	}
	
	// 轮播图设置
	public function indexAction() {
		$adv = M("DistributionShopAdv")->where(array('cid' => $this->aid))->find();
		if ( !$adv ) {
			$adv = array(
				'cid' => $this->aid,
			);
			$adv['id'] = M("DistributionShopAdv")->add($adv);
			if ( !$adv['id'] ) {
				$this->error("初始数据失败");
			}
		} else {
			$adv['config'] = (array)unserialize($adv['config']);
		}
		$this->assign("adv", $adv);
		$this->display();
	}
	
	// 提交轮播图设置
	public function indexPostAction() {
		$d = D('DistributionShopAdv');
		$d->create() and false !== $d->save() and $this->ajaxSuccess("保存成功");
		$this->ajaxError("保存失败");
	}
	
	// 首页地址
	public function urlAction() {
		$adv = M('DistributionShopAdv')->where(array('cid=%d', $this->aid))->find();
		$adv['url'] = url('Home', 'DisShopAdv', 'show', "sid={$this->aid}", true);
		$this->assign('adv', $adv);
		$this->display();
	}
	
}